package com.hs.sfzy.controller;

import com.hs.sfzy.entity.ClassQuestion;
import com.hs.sfzy.service.ClassQuestionService;
import com.hs.sfzy.until.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ClassQuestionController
 * @Description TODO
 * @Author Chen
 * @Date 2025年08月13日 11:14
 * @Version 1.0
 */
@RestController
@RequestMapping("/classQuestion")
public class ClassQuestionController {
    @Autowired
    private ClassQuestionService classQuestionService;

    @GetMapping("all")
    public R getAllClassQuestion(){
        List<ClassQuestion> allClassQuestion = classQuestionService.getAllClassQuestion();
        return R.ok(allClassQuestion);
    }

    @GetMapping("{userId}")
    public R getClassQuestionList(@PathVariable("userId") Integer useId) {
        List<ClassQuestion> classQuestionList = classQuestionService.getClassQuestionList(useId);
        return R.ok(classQuestionList);
    }

    @PostMapping("add")
    public R addClassQuestion(@RequestBody ClassQuestion classQuestion) {
        Integer integer = classQuestionService.addClassQuestion(classQuestion);
        return integer > 0 ? R.ok() : R.fail();
    }
    @GetMapping("getById/{id}")
    public R getClassQuestion(@PathVariable("id") Integer id) {
        ClassQuestion classQuestion = classQuestionService.getClassQuestion(id);
        return classQuestion != null ? R.ok(classQuestion) : R.fail();
    }
}
